package com.fudan.sys.service;

import java.util.concurrent.ConcurrentHashMap;

public class AppCache {

	public static ConcurrentHashMap<String, Integer> ipCache = new ConcurrentHashMap<>();
	private static Integer red = 50;
	
	public static void failIp(String ip) {
		if(ipCache.containsKey(ip)) {
			ipCache.put(ip,ipCache.get(ip)+1);
		}else {
			ipCache.put(ip, 1);
		}
	}
	
	public static void goodIp(String ip) {
		if(ipCache.containsKey(ip)) {
			ipCache.remove(ip);
		}
	}
	
	public static boolean checkIp(String ip) {
		if(ipCache.containsKey(ip)) {
			return ipCache.get(ip)<red;
		}
		return true;
	}
}
